'''
Created on Dec 16, 2010

@author: mwicat
'''

import logging
logger = logging.getLogger(__name__)
import inbox
import messaging
import e32

import core
from core import SniffyCmd

   
class SmsService(core.BaseRPCService):
    
    def __init__(self):
        self.inbox = inbox.Inbox()
        
    def box_handler(self, id):
        e32.ao_sleep(0.5)
        cmd = SniffyCmd(user=self.inbox.address(id), cmdln=self.inbox.content(id))
        self.dispatch_cmd(cmd)
        if self.cmd_handler:
            self.inbox.delete(id)
    
    def start_service(self):
        logger.debug('starting sms service...')
        self.inbox.bind(self.box_handler)
        
    def stop_service(self):
        pass
        
        
class SmsShellHandler:
    
    def handle_error(self, shell, msg):
        messaging.sms_send(shell.master, msg)
        
    def handle_result(self, shell, msg):
        messaging.sms_send(shell.master, msg)
        